home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group97a.txt
/
000101_icon-group-sender _Wed Apr 2 09:35:43 1997.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
3KB
Received: by cheltenham.cs.arizona.edu; Thu, 3 Apr 1997 06:18:11 MST
Date: Wed, 2 Apr 1997 09:35:43 -0800 (PST)
From: Tom Mitchell <mitch@relay.csd.SGI.COM>
To: Norman Ramsey <nr@cs.virginia.edu>
Cc: tc@charlie.cns.iit.edu, icon-group@cs.arizona.edu
Subject: Re: file locking in unix Icon
In-Reply-To: <199704011939.OAA19258@archive.cs.Virginia.EDU>
Message-Id: <Pine.SGI.3.94.970402084643.12938F-100000@roll.csd.sgi.com>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 2635
If you want to go fast and or be reliable there is work to do.
A simple spin loop is brutal on the system. It is implicit that
another process must run to free the lock. Thus it is important
to let that other process run. See the bsd system call nap() or
sleep(0). Busy wait loops are evil.
If the system is a true multiprocessing system spin locks might
play as long as the number of possible spinners is equal to or
less than the number of processes AND the time in the lock is
very small compared to the slice time.
On a single processor system or an oversubscribed multiprocessing
machine it is also important to ensure fair sharing of the locked
resources. It is very easy to have one process capture the lock.
Consider the odds that a given process will time slice out while
holding the lock. The ratio of locked vs. unlocked time matters
here. Again see the bsd system call nap() or sleep(0) and
consider "stepping aside" after the unlock().
Also if more than one lock or locked file is involved you will
need to eliminate deadlock risks by design. Check out
"Concurrent Programming... by Gregory Andrews or other operating
system texts like Per Brinch Hanson(sp).
It may be that the best way to get where you need to be is to
look at all the work that needs to be done then hide that in a
small set of modules/functions that you can improve over time.
Start with something simple and correct then work for speed...
Networking adds more ...
On Tue, 1 Apr 1997, Norman Ramsey wrote:
> To: tc@charlie.cns.iit.edu
> Cc: icon-group@cs.arizona.edu
> Subject: Re: file locking in unix Icon
>
> Sounds like I'll have to spin:
>
> f := &null
> while /f do f := open("lockfile", "c")
>
> does this sound right?
Close but not strong enough of itself without OS support of
exclusive locking of the file by the operating system. Check out
mail file locking in public packages like pine or elm, also vipw.
Consider a look into perl because there are some perl library
packages that work when the OS does not support strong locking.
i.e. build on a working lock strategy, building from scratch is
hard to get right (but fun).
Know also that NFS does not support locking of files and depends
on an external agent like 'lockd' to do the very hard work and
make it look as if NFS does support locking. Again watch for
deadlocks.
Spinning forever is a big risk. Always build in an escape or
some "continue, retry, abort" sequence.
> Norman
>
--
Thomas Mitchell -- mitch@sgi.com mitch@relay.csd.sgi.com mitch@acm.org
"Spring has sprung the grass is riz... I wonder where the birdies is."